package com.sskj.qiangjin.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.qiangjin.R;
import com.sskj.qiangjin.bean.CommonBean;
import com.sskj.qiangjin.bean.HelpCenterBean;
import com.sskj.qiangjin.presenter.FAQActivityPresenter;
import com.sskj.qiangjin.ui.adapter.ExpandAdapter;
import com.sskj.qiangjin.ui.adapter.Level0Item;
import com.sskj.qiangjin.ui.adapter.Level1Item;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by QinKang on 2018/12/29.
 */

@Route(path = RConfig.APP_FAQ)//常见问题
public class FAQactivity extends BaseActivity<FAQActivityPresenter> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private ExpandAdapter expandAdapter;
    private ArrayList<MultiItemEntity> list = new ArrayList<>();

    @Override
    protected int getLayoutResId() {
        return R.layout.app_activity_faq;
    }

    @Override
    public FAQActivityPresenter getPresenter() {
        return new FAQActivityPresenter();
    }


    @Override
    public void initView() {
        setTitle(App.INSTANCE.getString(R.string.app_activity_faq));
        mPresenter.getCommonData();

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        expandAdapter = new ExpandAdapter(list);
        recyclerView.setAdapter(expandAdapter);
    }

    public void updataUI(CommonBean commonBean) {
        list.clear();
        Level0Item level0Item = new Level0Item("什么是抢金");
        Level0Item level0Item1 = new Level0Item("奖池介绍");
        Level0Item level0Item2 = new Level0Item("游戏公平性");
        Level0Item level0Item3 = new Level0Item("自动逃跑");
        CommonBean.PlayInfoBean play_info = commonBean.getPlay_info();
        List<CommonBean.PlayInfoBean.GameBean> game = play_info.getGame();
        for (int i = 0; i < game.size(); i++) {
            Level1Item level1Item = new Level1Item(game.get(i).getTitle(), game.get(i).getContent().replaceAll("\\|", "\n"));
            level0Item.addSubItem(level1Item);
        }
        List<CommonBean.PlayInfoBean.PresentBean> present = play_info.getPresent();
        for (int i = 0; i < present.size(); i++) {
            Level1Item level1Item = new Level1Item(present.get(i).getTitle(), present.get(i).getContent().replaceAll("\\|", "\n"));
            level0Item1.addSubItem(level1Item);
        }
        List<CommonBean.PlayInfoBean.FairBean> fair = play_info.getFair();
        for (int i = 0; i < fair.size(); i++) {
            Level1Item level1Item = new Level1Item(fair.get(i).getTitle(), fair.get(i).getContent().replaceAll("\\|", "\n"));
            level0Item2.addSubItem(level1Item);
        }
        List<CommonBean.PlayInfoBean.FleeBean> flee = play_info.getFlee();
        for (int i = 0; i < flee.size(); i++) {
            Level1Item level1Item = new Level1Item(flee.get(i).getTitle(), flee.get(i).getContent().replaceAll("\\|", "\n"));
            level0Item3.addSubItem(level1Item);
        }
        list.add(level0Item);
        list.add(level0Item1);
        list.add(level0Item2);
        list.add(level0Item3);
        expandAdapter.notifyDataSetChanged();

    }


}
